﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
//using Model;

/// <summary>
/// Description résumée de ActiviteSiteLinkManager
/// </summary>
/// 
namespace DAL
{
    public class ActiviteSiteLinkManager : IActiviteSiteLinkManager
    {
        private IAATOEntities dbService;

        public ActiviteSiteLinkManager()
        {
            dbService = new IAATOEntities();
        }

        public bool addActiviteSiteLink(ACTIVITE_SITE_LINK activiteSiteLink)
        {
            try
            {
                dbService.ACTIVITE_SITE_LINKJeu.AddObject(activiteSiteLink);
                dbService.SaveChanges();

                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }

        public bool deleteActiviteSiteLink(int activiteId, int siteId)
        {
            try
            {
                ACTIVITE_SITE_LINK activiteSiteLink = (from l in dbService.ACTIVITE_SITE_LINKJeu
                             where l.ACTIVITEID == activiteId && l.SITEID == siteId
                             select l).First();

                dbService.DeleteObject(activiteSiteLink);
                dbService.SaveChanges();
                return true;
            }

            catch (Exception ex)
            {
                return false;
            }

        }

        public List<ACTIVITE_SITE_LINK> getAllActiviteSiteLinks()
        {
            try
            {
                return (from l in dbService.ACTIVITE_SITE_LINKJeu
                        orderby l.SITEID
                        select l).ToList();
            }
            catch (Exception ex)
            {
                return null;
            }
        }

        public ACTIVITE_SITE_LINK getActiviteSiteLinkByIds(int activiteId, int siteId)
        {
            try
            {
                return (from l in dbService.ACTIVITE_SITE_LINKJeu
                        where l.ACTIVITEID == activiteId && l.SITEID == siteId
                        select l).First();
            }
            catch (Exception ex)
            {
                return null;
            }
        }
    }
}